package gui;
import guiDisplay.MovieComment;
import guiDisplay.MovieData;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;

import logic.ToGuiFacade;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class pnlMovieDisplay extends javax.swing.JPanel {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private JLabel lblMoviePicture;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JButton rateMovie;
	private JButton backBtn;
	private JLabel jLabel7;
	private JLabel lblRaters;
	private JLabel lblRating;
	private JLabel lblLength;
	private JLabel lblLanguage;
	private JLabel lblDirector;
	private JLabel lblCategory;
	private JScrollPane jScrollPane1;
	private JPanel pnlUserComments;
	private JLabel jLabel6;
	private JLabel jLabel1;
	private JLabel lblMovieName;
	private String _user;
	private String _movieName;

	public pnlMovieDisplay(MovieData data, String user) {
		super();
		_user = user;
		initGUI(data);
	}

	private void initGUI(MovieData data) {
		try {
			this.setPreferredSize(new java.awt.Dimension(1014, 776));
			this.setLayout(null);
			this.setBackground(new java.awt.Color(255,128,0));
			{
				lblMoviePicture = new JLabel();
				this.add(lblMoviePicture);
				System.out.println(data.getPicture());
				try{
					lblMoviePicture.setIcon(new ImageIcon(ImageIO.read(getClass()/*.getClassLoader()*/.getResource("/"+data.getPicture()))));//new ImageIcon(getClass().getClassLoader().getResource(data.getPicture())));
				}catch(IllegalArgumentException e){
					JOptionPane.showMessageDialog(null, "COULD NOT FIND IMAGE!!!","Error",JOptionPane.ERROR_MESSAGE);
				}
				lblMoviePicture.setBounds(524, 0, 480, 711);
				lblMoviePicture.setBackground(new java.awt.Color(255,128,0));
				lblMoviePicture.setOpaque(true);
			}
			{
				_movieName = data.getName();
				lblMovieName = new JLabel();



				this.add(lblMovieName);
				lblMovieName.setText("<html><u>" + data.getName() + " (" + data.getYear() + ")</u></html>");
				System.out.println((lblMovieName.getText().length()/18));
				lblMovieName.setBounds(24, 22, 492, 50*(lblMovieName.getText().length()/18));
				lblMovieName.setFont(new java.awt.Font("Arial",1,48));
				lblMovieName.setBackground(new java.awt.Color(255,128,0));
			//	lblMovieName.setSize(lblMovieName.getPreferredSize());
				lblMovieName.validate();
			}
			{
				jLabel1 = new JLabel();
				this.add(jLabel1);
				jLabel1.setText("Category:");
				jLabel1.setBounds(68, 191, 71, 14);
				jLabel1.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel2 = new JLabel();
				this.add(jLabel2);
				jLabel2.setText("Director:");
				jLabel2.setBounds(68, 217, 71, 14);
				jLabel2.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel3 = new JLabel();
				this.add(jLabel3);
				jLabel3.setText("Language:");
				jLabel3.setBounds(68, 245, 71, 14);
				jLabel3.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel4 = new JLabel();
				this.add(jLabel4);
				jLabel4.setText("Length:");
				jLabel4.setBounds(68, 274, 71, 14);
				jLabel4.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel5 = new JLabel();
				this.add(jLabel5);
				jLabel5.setText("Rating:");
				jLabel5.setBounds(68, 298, 71, 14);
				jLabel5.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel6 = new JLabel();
				this.add(jLabel6);
				jLabel6.setText("Raters:");
				jLabel6.setBounds(283, 298, 52, 16);
				jLabel6.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblCategory = new JLabel();
				this.add(lblCategory);
				lblCategory.setText(data.getCategory());
				lblCategory.setBounds(151, 191, 221, 14);
				lblCategory.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblDirector = new JLabel();
				this.add(lblDirector);
				lblDirector.setText(data.getDirector());
				lblDirector.setBounds(151, 217, 126, 14);
				lblDirector.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblLanguage = new JLabel();
				this.add(lblLanguage);
				lblLanguage.setText(data.getLanguage());
				lblLanguage.setBounds(151, 245, 126, 14);
				lblLanguage.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblLength = new JLabel();
				this.add(lblLength);
				lblLength.setText(data.getLength());
				lblLength.setBounds(151, 274, 126, 14);
				lblLength.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblRaters = new JLabel();
				this.add(lblRaters);
				lblRaters.setText(data.getRaters());
				lblRaters.setBounds(335, 299, 96, 15);
				lblRaters.setBackground(new java.awt.Color(255,128,0));
			}
			{
				lblRating = new JLabel();
				this.add(lblRating);
				lblRating.setText(data.getRating());
				lblRating.setBounds(151, 298, 126, 14);
				lblRating.setBackground(new java.awt.Color(255,128,0));
			}
			{
				jLabel7 = new JLabel();
				this.add(jLabel7);
				jLabel7.setText("User comments:");
				jLabel7.setBounds(28, 326, 149, 15);
				jLabel7.setBackground(new java.awt.Color(255,128,0));
			}
			{
				backBtn = new JButton();
				this.add(backBtn);
				backBtn.setText("Back");
				backBtn.setBounds(36, 740, 75, 21);
				backBtn.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						backBtnActionPerformed(evt);
					}
				});
			}
			{
				rateMovie = new JButton();
				this.add(rateMovie);
				rateMovie.setText("Rate this movie");
				rateMovie.setBounds(337, 740, 165, 21);
				rateMovie.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						rateMovieActionPerformed(evt);
					}
				});
			}
			{
				pnlUserComments = new JPanel();
				this.add(pnlUserComments);
				BoxLayout pnlUserCommentsLayout = new BoxLayout(pnlUserComments, javax.swing.BoxLayout.Y_AXIS);
				pnlUserComments.setLayout(pnlUserCommentsLayout);
				pnlUserComments.setBounds(28, 347, 463, 378);
				pnlUserComments.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				int size = 0 ;
				{					
					for(MovieComment c : data.getComments()){
						pnlUserComment p = new pnlUserComment(c);
						pnlUserComments.add(p);
						size+=p.getHeight();
					}
					
				}
				pnlUserComments.setOpaque(false);
				pnlUserComments.setBackground(new java.awt.Color(255,128,0));
				{
					jScrollPane1 = new JScrollPane();
					pnlUserComments.add(jScrollPane1);
					jScrollPane1.setBounds(28, 296, 481, 324);
					jScrollPane1.setBackground(new java.awt.Color(255,128,0));
					jScrollPane1.setOpaque(false);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void backBtnActionPerformed(ActionEvent evt) {
		ToGuiFacade.getInstance().back();
	}

	private void rateMovieActionPerformed(ActionEvent evt) {
		//String movie = lblMovieName.getText();
		ToGuiFacade fac= ToGuiFacade.getInstance();
		fac.changeScreen(new pnlAddRating(_user, _movieName));
		//ToGuiFacade fac= ToGuiFacade.getInstance();
		//fac.changeScreen(new pnlAddRating(_user));
	}

}
